package com.cn.lb.support;

/**
 * @author: chenyuncong
 * @Date: 2020/3/10 15:11
 * 使用ThreadLocal 来保证gateway和ribbon 上下文 之间传递参数
 */
public class RibbonFilterContextHolder {
    private static final ThreadLocal<RibbonFilterContext> contextHolder = new InheritableThreadLocal<RibbonFilterContext>() {
        @Override
        protected RibbonFilterContext initialValue() {
            return new DefaultRibbonFilterContext();
        }
    };

    public static RibbonFilterContext getCurrentContext() {
        return contextHolder.get();
    }

    public static void clearCurrentContext() {
        contextHolder.remove();
    }
}
